<template>
  <div class='search'>
    <f-drawer ref='financeDrawer' :title='drawerTitle' width='90%' @submit='handleSubmit' @visibleChange='visibleChange'>
      <finance-form ref='form1' v-if="drawerVisible&&current=='form1'"></finance-form>
      <finance-details ref="form2" v-if="drawerVisible&&current=='form2'"></finance-details>
    </f-drawer>
  </div>
</template>
<script>
import financeForm from "./finance_form.vue"
import FinanceDetails from "@/views/module/business/finance/finance_details"

export default {
  name: "financeDrawer",
  props: {},
  data() {
    return {
      refs: this.$refs,
      drawerVisible: false,
      isEdit: false,
      title: "",
      current: "form1",
      formData: {},
      forms: [
        "form1"
      ]
    }
  },
  methods: {
    showDrawer(data,formName) {
      this.isEdit = false
      if (data && data.financeId) {
        this.isEdit = true
        this.formData = data
      } else {
        this.formData = {}
      }
      this.refs["financeDrawer"].show()
      this.tabClick(formName)
    },
    handleSubmit(callback) {
      this.refs[this.current].handleSubmit(callback)
    },
    visibleChange(drawerVisible) {
      this.drawerVisible = drawerVisible
    },
    tabClick(name) {
      this.current = name
      if (this.current === "form1") {
        this.title = this.isEdit ? "编辑对账表" : "添加对账表"
      }
      if (this.current === "form2") {
        this.title = this.formData.deptName+this.formData.financeMonth+"月-对账表"
      }
      this.$nextTick(() => {
        this.refs[this.current].setData(this.formData)
      })
    }
  },
  computed: {
    drawerTitle: function() {
      return this.title
    }
  },
  created() {
  },
  components: { FinanceDetails, financeForm }
}
</script>

<style scoped lang='less' rel='stylesheet/less'>

</style>
